import { defineConfig } from "vite";
import { resolve } from "node:path";
import vue from "@vitejs/plugin-vue";
import dts from "vite-plugin-dts";
import tsx from "@vitejs/plugin-vue-jsx";

// https://vite.dev/config/
export default defineConfig({
  build: {
    lib: {
      // 入口文件
      entry: resolve(process.cwd(), "./src/lib/index.ts"),
      // 包名称
      name: "vue-canteen",
      formats: ["es", "umd"],
      fileName: "vue-canteen",
    },
    rollupOptions: {
      // 确保需要外部处理的依赖包
      external: "vue",
      output: {
        // 在UMD模式下，为外部依赖提供一个全局变量
        globals: {
          canteen: "canteen",
          vue: "vue",
        },
      },
    },
  },
  plugins: [
    vue(),
    dts({
      tsconfigPath: "./tsconfig.app.json",
    }),
    tsx(),
  ],
});
